package com.tools.scanner.ui.qrcode.scanner

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.mlkit.vision.barcode.common.Barcode
import com.tools.scanner.databinding.FragmentEmailScannerBinding
import com.tools.scanner.utils.sendEmail

class EmailFragment : BaseScannerFragment() {

    private lateinit var mBinding: FragmentEmailScannerBinding

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        mBinding = FragmentEmailScannerBinding.inflate(inflater, container, false)
        return mBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val emailInfo = getData(Barcode.Email::class.java) ?: return

        mBinding.tvEmail.text = emailInfo.address
        mBinding.tvSubject.text = emailInfo.subject
        mBinding.tvBody.text = emailInfo.body

        mBinding.tvSend.setOnClickListener {
            emailInfo.sendEmail()
        }
    }

}